package guoanmaker.operator.business.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.service.PersonalFinanceProjectServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

/**
 *  
 * 金融项目及审批记录相关接口
 * @author zhouyu 
 * @ClassName: PersonalFinanceProjectController
 * @Description: PersonalFinanceProjectController 
 * @date 2017/12/19 
 */
@RestController
@RequestMapping(ApiController.OPERATOR_FINANCE_PROJECT)
public class PersonalFinanceProjectController {
	
	@Autowired
	private PersonalFinanceProjectServiceInterface personalFinanceProjectServiceInterface;
	
	@ApiOperation(value = "根据状态,项目名称查询所有的项目", notes = "根据状态，项目名称查询所有的项目")
    @PostMapping(value = "getFinanceProjectByAll")
	public AjaxJson getFinanceProjectByAll(Integer sort,String name,Integer status,Integer page,Integer size){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalFinanceProjectServiceInterface.getFinanceProjectByAll(sort, name,status, page, size));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value = "根据状态查询所有的项目", notes = "根据状态查询所有的项目")
    @PostMapping(value = "getFinanceProjectByStatus")
	public AjaxJson getFinanceProjectByStatus(Integer status,Integer page,Integer size){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalFinanceProjectServiceInterface.getFinanceProjectByStatus(status, page, size));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value = "项目的重要级别变更", notes = "项目的重要级别变更")
    @PostMapping(value = "importantLevelChange")
	public AjaxJson importantLevelChange(String id,Integer importantLevel){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalFinanceProjectServiceInterface.importantLevelChange(id, importantLevel));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("变更失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value = "根据id查询项目", notes = "根据id查询项目")
	@PostMapping(value = "getFinanceProjectById")
	public AjaxJson getFinanceProjectById(String id,Integer status){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalFinanceProjectServiceInterface.getFinanceProjectById(id,status));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value = "项目审核", notes = "项目审核")
	@PostMapping(value = "financeProjectAuditing")
	public AjaxJson financeProjectAuditing(String pid,String operatorUserName,int approvalInfo,
			String financeProjectRefuse,String refuseContent){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalFinanceProjectServiceInterface.financeProjectAuditing( pid, operatorUserName, approvalInfo,
					 financeProjectRefuse, refuseContent));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("审核失败");
		}
		return ajaxJson;
	}
	
	
	
	@ApiOperation(value = "新增金融项目拒绝原因列表", notes = "新增金融项目拒绝原因列表")
	@PostMapping(value = "insertFinanceProjectRefuse")
	public AjaxJson insertFinanceProjectRefuse(String operatorUserName,String typeName){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalFinanceProjectServiceInterface.insertFinanceProjectRefuse(operatorUserName,typeName));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("新增失败");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "修改金融项目拒绝原因列表", notes = "修改金融项目拒绝原因列表")
	@PostMapping(value = "updateFinanceProjectRefuse")
	public AjaxJson updateFinanceProjectRefuse(String id,String operatorUserName,String typeName){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalFinanceProjectServiceInterface.updateFinanceProjectRefuse(id,operatorUserName,typeName));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("修改失败");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "删除金融项目拒绝原因列表", notes = "删除金融项目拒绝原因列表")
	@PostMapping(value = "deleteFinanceProjectRefuse")
	public AjaxJson deleteFinanceProjectRefuse(String ids){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalFinanceProjectServiceInterface.deleteFinanceProjectRefuse(ids));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("删除失败");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "根据条件分页查询金融项目拒绝原因列表", notes = "根据条件分页查询金融项目拒绝原因列表")
	@PostMapping(value = "selectFinanceProjectRefuseByName")
	public AjaxJson selectFinanceProjectRefuseByName(String typeName,Integer page,Integer size){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalFinanceProjectServiceInterface.selectFinanceProjectRefuseByName( typeName, page, size));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "查询所有金融项目拒绝原因列表", notes = "查询所有金融项目拒绝原因列表")
	@PostMapping(value = "selectFinanceProjectRefuseList")
	public AjaxJson selectFinanceProjectRefuseList(){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalFinanceProjectServiceInterface.selectFinanceProjectRefuseList());
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "下载项目", notes = "下载项目")
	@GetMapping(value = "downloadFile")
	public void downloadFile(String urlstr,String fileName,HttpServletResponse response){
		personalFinanceProjectServiceInterface.downloadFile( urlstr, fileName, response);
	}
	
	
}
